package View.Index;

import View.Dorm.ChangeDorm;
import View.Message.HistoryMsg;
import View.Message.NewMsg;
import View.PayTheFeet.PayTheFeets;
import View.Repair.RepairPage;
import View.apply.AddOutApply;
import View.apply.IntoSchool;
import domain.User;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Index_user extends JFrame {



    public Index_user(User user){
        init();
        componentInit(user);
    }

    public void init(){
        this.setTitle("主页");
        this.setSize(632,442);
        this.setResizable(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);
    }

    public void componentInit(User user){
        //------------------JLabel--------------------
        JLabel label1= new JLabel();
        label1.setText(user.getUsername()+"欢迎来到宿舍管理系统你现在的身份是"+user.getType()+"请在菜单栏选择操作");
        label1.setBounds(100,49,393,161);
        JLabel label2= new JLabel();
/*        label2.setText("欢迎回来张三,你现在的身份是user");
        label2.setBounds(382,315,198,82);*/

        //Menu
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("缴费");
        JMenuItem item = new JMenuItem("交点击缴费");


        menu.add(item);


        JMenu menu1 = new JMenu("报修");
        JMenuItem item4 = new JMenuItem("点击填写报修详情");
        menu1.add(item4);

        JMenu menu2 = new JMenu("外出申请");
        JMenuItem item8 = new JMenuItem("点击填写外出申请");
        menu2.add(item8);

        JMenu menu3 = new JMenu("宿舍更换");
        JMenuItem item9 = new JMenuItem("点击填写填写申请");
        menu3.add(item9);

        JMenu menu4 = new JMenu("返校签到");
        JMenuItem item10 = new JMenuItem("点击进入签到界面");
        menu4.add(item10);

        JMenu menu5 = new JMenu("消息");
        JMenuItem item11 = new JMenuItem("查看未读消息");
        JMenuItem item12 = new JMenuItem("查看历史消息");
        menu5.add(item11);
        menu5.add(item12);

        menuBar.add(menu);
        menuBar.add(menu1);
        menuBar.add(menu2);
        menuBar.add(menu3);
        menuBar.add(menu4);
        menuBar.add(menu5);

        this.add(label1);
        this.add(label2);
        this.setJMenuBar(menuBar);

        item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new PayTheFeets(user).setVisible(true);
            }
        });

        item4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new RepairPage(user).setVisible(true);
            }
        });

        item8.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new AddOutApply(user).setVisible(true);
            }
        });

        item9.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new ChangeDorm(user).setVisible(true);
            }
        });

        item10.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new IntoSchool(user).setVisible(true);
            }
        });

        item11.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new NewMsg(user).setVisible(true);
            }
        });

        item12.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new HistoryMsg(user).setVisible(true);
            }
        });
    }
}
